package UF_MICRO;

import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.TextField;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

public class Example {
    class DBTestMidlet extends MIDlet {

        private Display display;
        private int nextRecordId;

        public DBTestMidlet() {
            display = Display.getDisplay(this);

            RecordStore store = null;
            try {
                store = RecordStore.openRecordStore("TestStore", true);
                nextRecordId = store.getNextRecordID();
            } catch (RecordStoreException e) {
                handleException(e);
                if (store != null) {
                    try {
                        store.closeRecordStore();
                    } catch (RecordStoreException e1) {
                        // ignore
                    }
                }
            }

            try {
                final String name = store.getName();
                display.setCurrent(new TextBox("", "Connected to database: " + name, 6000, TextField.ANY));
            } catch (Exception e) {
                handleException(e);
            }
        }

        private void handleException(Exception e) {
            display.setCurrent(new TextBox("Error", e.toString(), 60000, TextField.ANY));
        }

        public void startApp() {
        }

        public void pauseApp() {
        }

        public void destroyApp(boolean unconditional) {
        }
    }
}
